.NET: Fix JsonWireSerializedValue hash code contract - #7961
Draft
Daichi Isami (normalian) wants to merge 2 commits into
Draft
.NET: Fix JsonWireSerializedValue hash code contract#7961Daichi Isami (normalian) wants to merge 2 commits into
Daichi Isami (normalian) wants to merge 2 commits into
Conversation
Use JsonValueKind for a stable hash when structurally equal JSON values are compared, and add a regression test for separately parsed equivalent values.
Daichi Isami (normalian)
temporarily deployed
to
github-app-auth
August 31, 2026 09:52 — with
GitHub Actions
Inactive
Daichi Isami (normalian)
temporarily deployed
to
github-app-auth
August 31, 2026 09:52 — with
GitHub Actions
Inactive
Daichi Isami (normalian)
temporarily deployed
to
github-app-auth
August 31, 2026 09:53 — with
GitHub Actions
Inactive
Daichi Isami (normalian)
had a problem deploying
to
integration
August 31, 2026 09:55 — with
GitHub Actions
Failure
Daichi Isami (normalian)
had a problem deploying
to
integration
August 31, 2026 09:55 — with
GitHub Actions
Failure
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes hash consistency for structurally equal, separately parsed JSON wrappers.
Changes:
- Hashes
JsonWireSerializedValuebyJsonValueKind. - Adds a regression test for equivalent JSON documents.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
JsonWireSerializedValue.cs |
Changes hash-code generation. |
JsonSerializationTests.cs |
Tests equal wrapper hash codes. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| // JsonElement does not provide a structural hash code. ValueKind is necessarily equal | ||
| // whenever DeepEquals returns true, preserving the equality contract without recursively | ||
| // reimplementing JsonElement.DeepEquals semantics. | ||
| return this.Data.ValueKind.GetHashCode(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
JsonWireSerializedValue.Equals()uses structural JSON equality, while its previous hash code came fromJsonElement.GetHashCode(), which is not structural. Separately parsed equivalent JSON values could therefore compare equal but produce different hash codes.Description & Review Guide
JsonValueKindas the stable hash input and add a regression test for equivalent values parsed from separate JSON documents.JsonWireSerializedValueinstances now produce equal hash codes. Hash collisions between values of the same JSON kind are intentional to remain consistent withJsonElement.DeepEquals()without duplicating its semantics.ValueKind-based approach is appropriate for this internal delayed-deserialization wrapper.Related Issue
Fixes #7958
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.